package cn.net.shuxing.yifu.common.dto;

import cn.net.shuxing.yifu.common.constant.CodeConst;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;


@ApiModel(description = "返回结果")
@Data
public class DataDto {
    @ApiModelProperty("是否成功: 0成功，1失败")
    private int code = cn.net.shuxing.yifu.common.constant.CodeConst.OK;

    //异常信息
    @ApiModelProperty("错误原因")
    private String msg = "";


    @ApiModelProperty("数据条数")
    private Integer count;

    //返回的具体信息
    @ApiModelProperty("业务数据")
    private Object data;

    public static BaseDto error(String msg)
    {
        BaseDto baseDto = new BaseDto();
        baseDto.setCode(cn.net.shuxing.yifu.common.constant.CodeConst.ERROR);
        baseDto.setMsg(msg);
        return baseDto;
    }

    public static BaseDto ok(Object data)
    {
        BaseDto baseDto = new BaseDto();
        baseDto.setCode(cn.net.shuxing.yifu.common.constant.CodeConst.OK);
        baseDto.setData(data);
        return baseDto;
    }

    public boolean isError() {
        return code == CodeConst.ERROR;
    }

    /*
    返回格式:
    {
        "code": 0,
        "msg": "",
        "data": {}
    }
     */
}
